package com.tzbank.back.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tzbank.back.dao.MarketOperationMapper;
import com.tzbank.back.service.MarketOperationService;
import com.tzbank.entity.backstage.MarketOperation;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

/**
 * 营销运营配置
 * @author 蔡宇钿
 *2018年6月14日
 */
@Service(value="MarketOperationservice")
public class MarketOperationserviceImpl implements MarketOperationService {

	@Autowired
	private MarketOperationMapper marketOperationMapper;
	
	@Transactional
	@Override
	public Map<String, Object> deleteByMarketautoId(MarketOperation marketOperation) throws Exception {
		// 通过逻辑方式实现删除
		marketOperation.setStatus("0");
		marketOperation.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.marketOperationMapper.deleteByMarketautoId(marketOperation);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Override
	public Map<String, Object> getlistByMarkettarget(String target) throws Exception {
		// 按照target查询
		MarketOperation marketOperation = this.marketOperationMapper.getlistByMarkettarget(target);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(),marketOperation);
	}

	@Override
	public Map<String, Object> getlistMarket() throws Exception {
		// 查询全部
		List<MarketOperation> marketOperation = this.marketOperationMapper.getlistMarket();
		return null;
	}

	@Transactional
	@Override
	public Map<String, Object> addMarket(MarketOperation marketOperation) throws Exception {
		// 增加配置
		marketOperation.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		marketOperation.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		marketOperationMapper.addMarket(marketOperation);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}
	
	@Transactional
	@Override
	public Map<String, Object> modifyByMarketautoId(MarketOperation marketOperation) throws Exception {
		// 更新配置
		marketOperation.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.marketOperationMapper.modifyByMarketautoId(marketOperation);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
